package com.liming.product.controller;

import com.liming.common.pojo.dto.PageDTO;
import com.liming.common.pojo.dto.product.AddBrandDTO;
import com.liming.common.pojo.dto.product.UpdateBrandDTO;
import com.liming.common.pojo.vo.PageVO;
import com.liming.common.pojo.vo.product.BrandVO;
import com.liming.common.result.LMResult;
import com.liming.product.service.BrandMircoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liming
 * @date 2025/1/15
 */
@Slf4j
@RestController
@AllArgsConstructor
@Tag(name = "品牌接口-Service")
@RequestMapping("/service/brand")
public class BrandMircoController {

    private final BrandMircoService brandMircoService;

    @Operation(summary = "列表 - 品牌精选")
    @GetMapping("selected")
    public LMResult<List<BrandVO>> selectedBrand() {
        List<BrandVO> result = brandMircoService.selectedBrand();
        return LMResult.success(result);
    }

    @Operation(summary = "分页 - 品牌")
    @GetMapping
    public LMResult<PageVO<BrandVO>> page(PageDTO pageDTO, String name) {
        PageVO<BrandVO> page = brandMircoService.pageBrand(pageDTO, name);
        return LMResult.success(page);
    }

    @GetMapping("{id}")
    public LMResult<BrandVO> get(@PathVariable Long id) {
        BrandVO vo = brandMircoService.get(id);
        return LMResult.success(vo);
    }

    @PostMapping
    public LMResult<Boolean> add(@RequestBody AddBrandDTO dto) {
        Boolean result = brandMircoService.saveBrand(dto);
        return LMResult.success(result);
    }

    @Operation(summary = "更新 - 品牌精选")
    @PutMapping("selected/{id}")
    public LMResult<Boolean> updateSelected(@PathVariable Long id) {
        return LMResult.success(brandMircoService.updateSelectedById(id));
    }

    @PutMapping
    public LMResult<Boolean> update(@RequestBody UpdateBrandDTO updateBrandDTO) {
        Boolean result = brandMircoService.updateBrand(updateBrandDTO);
        return LMResult.success(result);
    }

    @DeleteMapping("{id}")
    Boolean delete(@PathVariable Long id){
        return brandMircoService.removeById(id);
    }

}
